//
//  OneSectionPickerViewController.m
//  YJlandlord
//
//  Created by 文彬 on 2018/6/29.
//  Copyright © 2018年 文彬. All rights reserved.
//

#import "PickerViewController.h"

@interface PickerViewController ()<UIPickerViewDelegate,
    UIPickerViewDataSource>

@end

@implementation PickerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = RGBACOLOR(0, 0, 0, 0.4);
    
    [self initPageControl];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)initPageControl{
    UIView *view = [[UIView alloc]init];
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
    [view makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.bottom.equalTo(@-216);
        make.height.equalTo(@50);
    }];
    
    UIButton *cancleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [cancleBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancleBtn setTitleColor:kTitleColor forState:UIControlStateNormal];
    cancleBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [view addSubview:cancleBtn];
    [cancleBtn makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.width.equalTo(@40);
        make.height.equalTo(@30);
        make.centerY.equalTo(view.centerY);
    }];
    [cancleBtn buttonClick:^{
        [self dismissViewControllerAnimated:YES completion:nil];
    }];
    
    UIButton *okBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [okBtn setTitle:@"确定" forState:UIControlStateNormal];
    [okBtn setTitleColor:kMainOriginColor forState:UIControlStateNormal];
    okBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [view addSubview:okBtn];
    [okBtn makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@-10);
        make.width.equalTo(@40);
        make.height.equalTo(@30);
        make.centerY.equalTo(view.centerY);
    }];
    
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel.font = [UIFont systemFontOfSize:15];
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = @"房屋户型";
    [view addSubview:titleLabel];
    [titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@200);
        make.centerY.equalTo(view.centerY);
        make.height.equalTo(@25);
        make.centerX.equalTo(view.centerX);
    }];
    
    UIPickerView *picker = [[UIPickerView alloc]init];
    picker.dataSource = self;
    picker.delegate  = self;
    picker.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:picker];
    [picker makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(@0);
        make.top.equalTo(view.bottom).offset(0.5);
    }];
}

#pragma makr UIPicker
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component __TVOS_PROHIBITED{
    return SCREEN_WIDTH/self.datas.count;
}
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{
    return 50;
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return self.datas.count;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    NSArray *arr =self.datas[component];
    return arr.count;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    return self.datas[component][row];
}

- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component NS_AVAILABLE_IOS(6_0){

    NSDictionary* titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                         [UIColor blackColor], NSForegroundColorAttributeName,
                                         [UIFont systemFontOfSize:10.0f], NSFontAttributeName,
                                         nil];
    
    NSAttributedString *restr = [[NSAttributedString alloc] initWithString:self.datas[component][row] attributes:titleTextAttributes];
    return restr;
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component __TVOS_PROHIBITED
{
    
}

@end
